// pages/detail/detail.js

const app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
var utils = require("../../utils/util.js");
var noLogin = require("../template/noLogin.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //轮播自动切换
    autoplay: true,
    //当前所在滑块的 index
    newindex: 0,
    //是否含有视频
    isVideo: true,
    //显示隐藏视频
    showVideo: true,
    //猜你喜欢的基础url
    baseGoodsImgUrl: 'https://rybc.0791jr.com/data/attachment/item/',
    //图文和评价状态切换
    activeIndex: 0,
    tab: ['图文详情', '商品评价'],
    //评价类型进行切换
    commentTypeSelected: 0,
    //评论内容
    comments: null,
    //遮罩层显示状态
    mask: true,
    //承诺保障弹窗
    promiseBox: true,
    //产品参数弹窗
    paramsBox: true,
    //购物车弹窗显示隐藏
    cartBox: true,
    //选择规格弹窗
    choice: true,
    //购买商品数量
    goodsNumber: 1,
    //已选规格下标，默认选择第一种规格
    specActive: 0,

    specActiveed: 0,
    //已选规格价格
    specActivePrice: 0,
    //已选规格库存
    inventory: 0,
    //已选商品限购数量
    limit: null,
    //判断是购物车弹窗还是立即购买
    joinOrBuy: null,
    //选择弹窗判断是购物车弹窗还是立即购买
    optjoinOrBuy: null,
    //是否收藏
    isCollect: null,
    ismiaoshashop: 1, //判断是否是秒杀商品
    maiosha: 0,//秒杀商品判断
    //购物车商品数量
    // dot: null,
    item_id: null,
    optionsData: null,
    hasUserInfo: true,   //判断是否获取了用户数据  默认true为获取了
    networkStatus: null,   //  判断网络状态
    automatic: false,     //视频自动播放
    share: true,       //分享弹窗
    imagePath: null,    //绘制的图片路径
    Poster: true,      //生成海报弹窗
    pathImg: null,    //商品图片海报
    qrcode: null,      //二维码海报生成
    qrwidth: null,   //绘图板外view的宽度
    qrheight: null,   //绘图板外view的高度
    allmarry: [],    //所有的规格
    marry: [],     //规格匹配
    nowmarry: 0,   //没有此类搭配
    p_min: 0,//最低价格
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    if (!!options.maiosha) {
      console.log(options.maiosha)
      var maiosha = options.maiosha
      this.setData({
        optionsData: options,
        maiosha: maiosha
      });
    } else {
      this.setData({
        optionsData: options,
        maiosha: 0
      });
    }
    this.init();
    this.getRect();
    wx.getNetworkType({
      success: (res) => {
        this.setData({
          networkStatus: res.networkType
        })
      }
    });
  },

  getRect: function () {
    const that = this;
    wx.createSelectorQuery().select('#the-id').boundingClientRect(function (rect) {
      rect.width   // 节点的宽度
      rect.height  // 节点的高度
      that.setData({
        qrwidth: rect.width,
        qrheight: rect.height
      })
    }).exec()
  },

  init() {
    const options = this.data.optionsData;
    wx.showLoading({ title: '加载中...' });
    let url, detail;
    const userId = app.globalData.userId;
    if (options.type == 1) {  //1 从秒杀跳转
      const info = JSON.parse(options.data);  //秒杀参数
      this.setData({ seckillData: info })
      if (info.status != 3 || !info.sellOut) {  //当前商品未结束或者未售完
        url = app.baseURL + 'Seckill&a=item_detail';  //秒杀接口
        detail = {
          user_id: userId,  //用户id
          item_id: info.item_id,  //商品id
          act_id: info.act_id,  //活动id
          guige_id: info.did,  //商品规格
        };
      } else { //其它跳入
        url = app.baseURL + 'Item&a=item_detail';
        detail = {
          item_id: info.item_id,
          user_id: userId
        };
      }
    } else if (options.type == 2) { //今日特价传单规格
      url = app.baseURL + 'Index&a=item_detail';
      detail = {
        item_id: options.item_id,
        userId: app.globalData.userId,
        guige_id: options.gui_id,
        acd_id: options.act_id
      }
    }
    this.setData({
      item_id: detail ? detail.item_id : options.item_id
    })
    //获取商品数据
    wx.request({
      url: url || app.baseURL + 'Item&a=item_detail',
      data: detail || {
        item_id: options.item_id,
        user_id: userId,
        path: '/pages/detail/detail?item_id=' + this.data.item_id
      },
      success: (res) => {
        if (res.data.status == 1 && res.statusCode == 200) {
          let data = res.data;
          if (data.info.info != null) {
            //调用wxParse解析html文本
            WxParse.wxParse('goodsinfo', 'html', data.info.info, this, 5);
          }
          if (data.code) {
            clearInterval(this.countFun); //清除定时器避免重复
            this.countFun = setInterval(() => {
              data.time--;  //时间自减
              data.time < 0 && clearInterval(this.countFun);  // 时间到了清除定时器
              this.setData({ ['data.time']: utils.seckill(data.time) });
            }, 1000);
          }
          data.sku_list.forEach(item => {
            if (item.list) {
              item.list.forEach(citem => {
                citem.isHasSpec = false; // 选中的样式
                citem.isCould = true; // true可以选的样式， false不可选的样式
              })
            }
          });
          let inventory = 0;
          data.list.forEach(item => {
            inventory += (item.inventory - 0);
          })
          this.setData({
            data: data,
            info: data.info,
            ['data.time']: data.code ? utils.seckill(data.time) : null,   //初始化显示时间
            isCollect: res.data.collect_status,
            //默认展示全部评价
            comments: data.comment,
            //默认显示价格区间、库存区间
            specActivePrice: data.info.price,
            // specActivePrice: data.list[0].price + ' ~ ' + data.list[data.list.length - 1].price,
            inventory: data.list[0].inventory, // 库存
            limit: data.list[0].limit_number || null,
            p_min: data.list[0].price,
          });
          console.log(data.list);
          wx.hideLoading();
          // if (this.data.networkStatus == 'wifi') {
          //   this.setData({
          //     automatic: true,
          //     showVideo: false,
          //     autoplay: false,
          //   })
          // }
          // if (this.data.data.item_img[1] == null) {
          //   this.setData({
          //     isVideo: false
          //   })
          // }
        }
      }
    });
  },
  //显示参数弹窗
  showParamsBox() {
    this.setData({
      paramsBox: !this.data.paramsBox,
      mask: !this.data.mask
    })
  },
  //视频播放时不可滑动，滑动则取消播放
  catchTouchMove: function (res) {
    console.log(11);
    this.setData({
      showVideo: true,
      autoplay: true,  //自动轮播
    })
    // return false;
  },

  //播放视频
  showVideo() {
    const that = this;
    if (this.data.networkStatus != 'wifi') {
      wx.showToast({
        title: '正在使用数据流量观看视频',
        icon: 'none'
      })
    }
    this.setData({
      automatic: true,
      showVideo: false,
      autoplay: false,  //不自动轮播
    })
  },
  //播放完毕隐藏vide，显示图片
  hiddVideo() {
    this.setData({
      showVideo: true,
      autoplay: true,   //自动轮播
    })
  },

  //图文和评价---选项卡切换
  tabClick(e) {
    this.setData({
      activeIndex: e.currentTarget.id
    });
  },

  //商品评价类型---选项卡切换
  commentTypeClick(e) {
    let comments;
    const index = e.currentTarget.dataset.index;
    if (index == 0) { comments = this.data.data.comment; }
    else if (index == 1) { comments = this.data.data.hpcomment; }
    else if (index == 2) { comments = this.data.data.zpcomment; }
    else if (index == 3) { comments = this.data.data.cpcomment; }
    this.setData({
      commentTypeSelected: index,
      comments: comments
    });
  },

  //评论---图片大图预览
  previewImage(e) {
    let base = 'https://rybc.0791jr.com/data/attachment/comment/';
    let index = e.currentTarget.dataset.index, //当前图片的下标
      imgs = e.currentTarget.dataset.targetimgs, //当前用户的评论图片
      imgURLs = [];
    //由于后台返回的图片url不是完整的，重新处理一下
    imgs.forEach((item) => { imgURLs.push(base + item.url) });
    //调用大图预览接口
    wx.previewImage({
      current: imgURLs[index], // 当前显示图片的https链接
      urls: imgURLs,  // 需要预览的图片https链接列表
      success: () => { }
    });
  },

  // getBanner(){
  //   wx.request({
  //     url: app.baseURL + 'Item&a=get_qrcode',
  //     data: {
  //       item_id: this.data.item_id,
  //       path: '/pages/detail/detail?item_id=' + this.data.item_id
  //     },
  //     success: (res) => {
  //       if (res.statusCode == 200) {
  //         if (res.data.status == 1) {
  //           wx.previewImage({
  //             current: ["https://rybc.0791jr.com/data/attachment/ewm/" + res.data.qrcode][0], // 当前显示图片的https链接
  //             urls: ["https://rybc.0791jr.com/data/attachment/ewm/" + res.data.qrcode],  // 需要预览的图片https链接列表
  //             success: () => { }
  //           })
  //         } else if (res.data.status == 0) {
  //           wx.showToast({
  //             title: "二维码获取失败，请稍后再试",
  //             icon: 'none'
  //           })
  //         }
  //       }
  //     }
  //   });
  // },

  //拨打客服电话
  call(e) {
    const tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel,
    })
  },

  //收藏商品
  onOffCollect(e) {
    //收藏
    if (!wx.getStorageSync('userInfo')) {
      noLogin.showNoLogin(this).then(() => {
        //用户授权后更新用户数据
        this.collect(e);
      }).catch(() => {
        this.setData({ hasUserInfo: false }); //判断用户未登录，弹出授权窗口
      });
    } else {
      this.setData({ hasUserInfo: true }); //判断用户已登录，关闭授权窗口
      this.collect(e);
    }
  },


  //收藏
  collect(e) {
    const state = this.data.collect_status;
    const userId = app.globalData.userId;
    const itemId = this.data.info.id;
    wx.showLoading({ title: '加载中...' });
    wx.request({
      url: app.baseURL + 'Item&a=collect&item_id=' + itemId + '&user_id=' + userId,
      success: (res) => {
        if (res.statusCode == 200) {
          //返回数据成功
          let data = res.data;
          if (data.status == 1 && data.info == '成功取消收藏') {
            wx.showToast({ title: '已取消收藏', icon: 'none' });
            this.setData({ isCollect: false });
          } else if (data.status == 1 && data.info == '收藏成功') {
            wx.showToast({ title: '收藏成功', icon: 'none' });
            this.setData({ isCollect: true });
          }
        }
      }
    });
  },

  //显示保障弹窗
  showPromiseBox() {
    this.setData({
      promiseBox: !this.data.promiseBox,
      mask: !this.data.mask
    })
  },

  // 选择参数--显示隐藏

  //购物车弹窗---显示隐藏
  showCart(e) {
    if (!wx.getStorageSync('userInfo')) {
      noLogin.showNoLogin(this).then(() => {
        this.setData({
          cartBox: !this.data.cartBox, //显示隐藏购物车弹窗
          mask: !this.data.mask, //显示隐藏遮罩层
          joinOrBuy: e.currentTarget.dataset.joinorbuy //判断是点击的加入购物车还是点击的立即购买
        });
      }).catch(() => {
        this.setData({ hasUserInfo: false }); //判断用户未登录，弹出授权窗口
      });
    } else {
      this.setData({
        hasUserInfo: true, //判断用户已登录，关闭授权窗口
        cartBox: !this.data.cartBox, //显示隐藏购物车弹窗
        mask: !this.data.mask, //显示隐藏遮罩层
        joinOrBuy: e.currentTarget.dataset.joinorbuy //判断是点击的加入购物车还是点击的立即购买
      });
      // console.log(this.data.joinOrBuy)
    }
  },

  //选择规格弹窗
  Choice() {
    this.setData({
      choice: !this.data.choice, //显示隐藏购物车弹窗
      mask: !this.data.mask, //显示隐藏遮罩层
    })
  },
  //分享
  Share() {
    this.setData({
      share: !this.data.share,  //显示隐藏分享弹窗
      mask: !this.data.mask, //显示隐藏遮罩层
    })
  },

  //取消分享弹窗
  CancelShare() {
    this.setData({
      share: !this.data.share,  //显示隐藏分享弹窗
      mask: !this.data.mask, //显示隐藏遮罩层
    })
  },

  //转发
  // onShareAppMessage: function(res){
  //   if (res.from === 'button') {
  //     // 来自页面内转发按钮
  //     console.log(res.target)
  //   }
  //   return {
  //     title: '自定义转发标题',
  //     path: '/page/user?id=123'
  //   }
  // },

  //购物车弹窗---点击确定按钮
  cartBoxClick(e) {
    let state = this.data.joinOrBuy,
      isSelect = this.data.specActiveed,
      nowmarry = this.data.nowmarry;
    let optstate = e.currentTarget.dataset.joinorbuy;

    console.log(optstate);
    //先判断是否选中规格
    if (isSelect == 0) {
      wx.showToast({
        title: '请选择规格',
        image: '/images/ico-close.png'
      })
      return;
    }
    //再判断有没有此类规格
    if (nowmarry == 1) {
      wx.showToast({
        title: '请重新选择哦~',
        image: '/images/ico-close.png'
      })
      return;
    }

    //加入购物车
    if (state === 'join' || optstate === 'join') {
      if (this.data.inventory == 0) {      //库存为0
        wx.showToast({
          title: '此规格没有库存了，看看其他的吧',
          icon: 'none'
        })
        return;
      }
      wx.showLoading({ title: '加载中...' });
      wx.request({
        url: app.baseURL + 'Car&a=itemAddCar',
        data: {
          gui_id: this.data.specActiveed,
          item_id: this.data.specItemIded,
          item_num: this.data.goodsNumber,
          user_id: app.globalData.userId
        },
        success: (res) => {
          if (res.statusCode == 200) {
            if (res.data.status == 1 || res.data.status == 2) {
              wx.showToast({ title: '宝贝在购物车等亲~', icon: 'none' });
              // this.setData({ dot: res.data.car_num });
              // app.setBadge(2, res.data.car_num);
              // wx.setStorageSync('car_num', res.data.car_num);
              // wx.hideLoading();
            }
          }
        }
      });
      this.setData({
        cartBox: true, //隐藏购物车弹窗
        mask: true, //隐藏遮罩层
        choice: true //隐藏选择弹窗
      });

      //购买
    } else if (state === 'buy' || optstate === 'buy') {
      if (this.data.inventory == 0){      //库存为0
        wx.showToast({
          title: '此规格没有库存了，看看其他的吧',
          icon: 'none'
        })
        return;
      }
      const options = this.data.optionsData,
        gui_id = this.data.specActiveed, //规格id
        item_num = this.data.goodsNumber, //商品数量
        item_id = this.data.specItemIded, //商品id
        user_id = app.globalData.userId, //用户id
        _type = (options.type == 1 || options.type == 2) ? 3 : 1;  //1限时秒杀，2特价促销
      wx.navigateTo({
        url: '/pages/placeorder/placeorder?type=' + _type + '&gui_id=' + gui_id + '&item_num=' + item_num + '&item_id=' + item_id + '&user_id=' + user_id
      })
    } else {
      wx.showToast({
        title: '当前商品限购数量为' + this.data.limit,
        icon: 'none'
      })
    }
  },

  //购物车弹窗---选择商品多规格
  OneSelectSpec(e) {
    const data = e.currentTarget.dataset;
    console.log(e);
    this.setData({
      specActiveed: data.gui_id, //选中的规格id
      specActive: data.gui_id, //选中的规格id
      specItemIded: data.item_id, //选中的商品id
      specActivePrice: data.price, //选中的规格价格
      inventory: data.inventory, //选中的规格库存数
      limit: data.limit || null //选中的商品限购数量
    })
  },

  //购物车弹窗---选择商品多属性多规格
  selectSpec(e) {
    this.setData({
      nowmarry: 0,
      allmarry: []
    })
    const that = this;
    const data1 = this.data;
    const dataset = e.currentTarget.dataset;
    let guige = null;  //匹配的规格字符串
    data1.data.list.forEach((item, index) => {
      this.data.allmarry.push(that.arrSort(item.guiges));
    })

    this.data.marry.length = this.data.data.sku_list.length;

    console.log(data1.data.sku_list);

    for (let i = 0; i < data1.data.sku_list.length; i++) {
      if (dataset.index == i) {
        if (data1.data.sku_list[dataset.index].list[dataset.index_x].isHasSpec == true) {
          this.setData({
            [`data.sku_list[${i}].list[${dataset.index_x}].isHasSpec`]: false,
            nowmarry: 1
          })

          let now = this.data.marry.indexOf(dataset.item_id);
          this.data.marry.splice(now, 1, undefined);
        } else {
          this.data.marry.splice(dataset.index, 1, dataset.item_id);
          for (let j = 0; j < data1.data.sku_list[i].list.length; j++) {
            this.setData({
              [`data.sku_list[${i}].list[${j}].isHasSpec`]: false
            })
          }
          this.setData({
            [`data.sku_list[${i}].list[${dataset.index_x}].isHasSpec`]: true
          })
        }

      }
    }

    let marrydq = [];
    for (var v = 0; v < this.data.marry.length; v++) {
      var exist = typeof (this.data.marry[v]) == 'undefined';
      marrydq.push(exist);
    }

    guige = this.data.marry.join("_");
    console.log(guige);
    console.log(this.data.marry);
    if (this.data.marry.length == data1.data.sku_list.length && marrydq.indexOf(true) == -1) {
      if (this.data.allmarry.indexOf(this.arrSort(guige.split("_"))) == -1) {
        wx.showToast({
          title: '没有此搭配哦~',
          icon: 'none',
        });
        that.setData({
          nowmarry: 1
        })
        return;
      } else {
        this.data.allmarry.forEach((item, index) => {
          if (this.arrSort(guige.split("_")) == item) {
            that.setData({
              specActivePrice: data1.data.list[index].price, //选中当前规格的价格
              inventory: data1.data.list[index].inventory,   //选中当前规格的库存
              specActiveed: data1.data.list[index].id,     //选中当前规格的id
              specItemIded: data1.data.list[index].item_id,  //选中当前规格的item_id
            })
          }
        })
      }
    } else {
      console.log(11);
      that.setData({
        nowmarry: 1
      })
      return;
    }
  },
  //数组重新排序从小到大
  arrSort(arr) {
    return arr.sort((a, b) => { return a - b }).join("_");
  },


  //购物车弹窗---商品数量增加
  addNumber() {
    if (this.data.limit && this.data.limit == this.data.goodsNumber) {
      wx.showToast({ title: '不能超过限购数量', icon: 'none', mask: true })
      return false
    }
    if (this.data.inventory <= this.data.goodsNumber) {
      wx.showToast({ title: '不能超过库存数量', icon: 'none', mask: true })
      return false
    }
    this.setData({
      goodsNumber: ++this.data.goodsNumber
    })
  },
  //购物车弹窗---商品数量减少
  reduceNumber() {
    if (this.data.goodsNumber <= 1) return;
    this.setData({
      goodsNumber: --this.data.goodsNumber
    })
  },
  //购物车弹窗---通过手机按键改变商品数量时
  inputValueChange(e) {
    let val = e.detail.value;
    //当回删到空的时候，自动返回数量1
    if (val == '' || val <= 0) return 1;
    if (this.data.limit && this.data.limit < val) {
      wx.showToast({ title: '不能超过限购数量', icon: 'none', mask: true })
      val = this.data.limit
    }
    if (Number(val) > Number(this.data.inventory)) {
      wx.showToast({ title: '不能超过库存数量', icon: 'none', mask: true })
      val = 1
    }
    this.setData({
      goodsNumber: val
    });
  },

  //跳转到购物车页面
  clickToShopcart() {
    wx.switchTab({
      url: '/pages/shopcart/shopcart',
    });
  },

  //用户确认授权
  WeChatUserInfo: function (e) {
    if (e.detail.userInfo) {
      this.setData({ hasUserInfo: true });//发起登录
      noLogin.getUserInfo(this);//用户授权后更新用户数据
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '拒绝微信授权将无法使用部分功能',
        success: res => {
          if (res.confirm) {
            this.setData({ hasUserInfo: true });
          }
        }
      })
    }
  },

  //点击遮罩层隐藏弹窗
  hideAllBox() {
    this.setData({
      //遮罩层隐藏
      mask: true,
      //承诺保障弹窗隐藏
      promiseBox: true,
      //产品参数弹窗隐藏
      paramsBox: true,
      //购物车弹窗隐藏
      cartBox: true,
      //选择规格弹窗隐藏
      choice: true,
      //分享弹窗隐藏
      share: true,
      //生成海报弹窗隐藏
      Poster: true,
    })
  },

  // 绘制图片
  DrawImg() {
    wx.showLoading({
      title: '海报生成中...'
    });
    const _this = this;
    // let path = null;  //获取商品图片
    // var qrcode = this.data.data.qrcode;        //获取二维码
    const context = wx.createCanvasContext('mycanvas');
    var title = this.data.data.info.title;
    var linnoe = title.substring(0, 16);
    var lintwo = title.substring(16, 30);
    wx.downloadFile({
      url: this.data.data.item_img[0][0],
      success: function (res) {
        if (res.statusCode === 200) {
          _this.data.pathImg = res.tempFilePath;
          context.setFillStyle('white')
          context.fillRect(0, 0, 542, 977)
          context.drawImage(_this.data.pathImg, 0, 0, 271, 271)
          context.setTextAlign('center')    // 文字居中
          context.setFillStyle('#000000')  // 文字颜色：黑色
          context.setFontSize(14)         // 文字字号
          // context.setTextAlign('center')
          context.fillText(linnoe, 132, 320)
          if (String(lintwo).length != 0) {
            context.fillText(lintwo + '...', (_this.data.qrwidth / 2), 343)
          }
          // context.fillText(lintwo + '...', 132, 348)
          context.setTextAlign('left')    // 文字居中
          context.setFillStyle('#ff0000')
          context.fillText("￥", 20, _this.data.qrheight)
          context.setFontSize(22);
          context.fillText(_this.data.p_min, 32, _this.data.qrheight)
          wx.downloadFile({
            url: _this.data.data.qrcode,
            success: function (res) {
              if (res.statusCode === 200) {
                console.log(_this.data.data.qrcode);
                _this.data.qrcode = res.tempFilePath;
                context.drawImage(_this.data.qrcode, _this.data.qrwidth - 96, _this.data.qrheight - 55, 80, 80)
                // context.setFillStyle('#999999')  // 文字颜色：黑色
                // context.setFontSize(8)         // 文字字号
                // context.fillText('扫描或长按小程序码', _this.data.qrwidth - 50, _this.data.qrheight + 40)
                context.stroke()
                context.draw()
                // console.log(_this.data.qrcode);
                
                setTimeout(function () {
                  wx.canvasToTempFilePath({
                    canvasId: 'mycanvas',
                    success: function (res) {
                      // console.log(res.tempFilePath)
                      _this.setData({
                        imagePath: res.tempFilePath
                      })
                      _this.setData({
                        share: !_this.data.share,  //显示隐藏分享弹窗
                        mask: false,  //显示隐藏遮罩层
                        Poster: !_this.data.Poster
                      })
                      wx.hideLoading()
                    }
                  })
                }, 2000)
              }
            }
          })
        }
      }
    })
  },

  // 保存海报
  storage() {
    wx.saveImageToPhotosAlbum({
      filePath: this.data.imagePath,
      success(res) {
        wx.showToast({
          title: '保存成功！',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },

  //获取当前swiper的下标
  bindchage(e) {
    this.setData({
      newindex: e.detail.current
    })

  },

  //轮播海报查看大图
  bigpicture(e) {
    var list = this.data.data.item_img[0];
    if (this.data.data.item_img[1] == null) {
      wx.previewImage({
        current: list[this.data.newindex], // 当前显示图片的https链接
        urls: list // 需要预览的图片https链接列表
      })
    } else {
      wx.previewImage({
        current: list[this.data.newindex - 1], // 当前显示图片的https链接
        urls: list // 需要预览的图片https链接列表
      })
    }
  },

  /**
 * 生命周期函数--监听页面卸载
 */
  onUnload: function () {
    clearInterval(this.countFun);   //停止定时器
  },

  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
    }
    let data = this.data;
    return {
      // title: app.globalData.title,
      title: this.data.data.info.title,
      path: '/pages/detail/detail?item_id=' + this.data.item_id,
      imageUrl: this.data.data.item_img[0][0],
      success: res => {
        console.log("转发成功")
        // 转发成功
        console.log(44)
      },
      fail: err => {
        // 转发失败
        console.log("转发失败")
      }
    }
  },

  //点击 跳转详情页
  clickToDetail(e) {
    let item_id = e.currentTarget.dataset.item_id;
    wx.navigateTo({
      url: '../detail/detail?item_id=' + item_id
    });
  },

})